package com.cs.club.application.controller;

import com.cs.club.application.dtos.ClubActivitiesDTO;
import com.cs.club.common.entity.BaseResponse;
import com.cs.club.common.utlis.ResultUtils;
import com.cs.club.domain.bos.ClubActivitiesBO;
import com.cs.club.domain.service.ClubActivitiesDomainService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/activities")
public class ClubActivitiesController {

    @Resource
    private ClubActivitiesDomainService clubActivitiesDomainService;

    @PostMapping("/add")
    public BaseResponse<Boolean> addClubActivities(ClubActivitiesDTO clubActivitiesDTO) {
        // 输出日志
        log.info("添加活动参数:{}", clubActivitiesDTO);
        ClubActivitiesBO clubActivitiesBO = new ClubActivitiesBO();
        BeanUtils.copyProperties(clubActivitiesDTO, clubActivitiesBO);
        return ResultUtils.success(clubActivitiesDomainService.addClubActivities(clubActivitiesBO));
    }

    /**
     * 删除活动
     */
    @PostMapping("/delete")
    public BaseResponse<Boolean> deleteClubActivities(ClubActivitiesDTO clubActivitiesDTO) {
        // 输出日志
        log.info("删除活动参数:{}", clubActivitiesDTO);
        ClubActivitiesBO clubActivitiesBO = new ClubActivitiesBO();
        BeanUtils.copyProperties(clubActivitiesDTO, clubActivitiesBO);
        return ResultUtils.success(clubActivitiesDomainService.deleteClubActivities(clubActivitiesBO));
   }

    @PostMapping("/update")
    public BaseResponse<Boolean> updateClubActivities(ClubActivitiesDTO clubActivitiesDTO) {
        // 输出日志
        log.info("修改活动参数:{}", clubActivitiesDTO);
        ClubActivitiesBO clubActivitiesBO = new ClubActivitiesBO();
        BeanUtils.copyProperties(clubActivitiesDTO, clubActivitiesBO);
        return ResultUtils.success(clubActivitiesDomainService.updateClubActivities(clubActivitiesBO));
    }
}
